<template>
  <div class="source-box my-work">
    <div class="add-tab-btn">
      <el-button type="primary" size="mini" @click="toCreate">新增</el-button>
    </div>
    <el-table :data="list" size="medium" @row-click="toDetil" :border="false" :show-header="false">
      <el-table-column label="抄送名称" align="left" prop="taskTitle"></el-table-column>
      <el-table-column label="更改时间" width="170" align="right">
        <template slot-scope="scope">
          <span class="common-table-item">更改时间：{{ scope.row.updateTime | formatDate('yyyy-MM-dd') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="40" align="right">
        <template slot-scope="scope">
          <el-button type="text el-icon-delete" @click.stop="deleteItem(scope.row.primaryKey)"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination v-if="queryParams.total > queryParams.pageSize" class="page-box t-right m-t-s" prev-text="上一页" next-text="下一页" layout="prev, pager, next" :total="queryParams.total" :current-page.sync="queryParams.currentPage" :page-size="queryParams.pageSize" @current-change="getInfo" />
  </div>
</template>

<script>
  import { apiCcManageList, apiCcManageListDelect } from '../../../api/process';
  import {formatDate} from '@/common/js/utils';
  export default {
    data() {
      return {
        queryParams: {
          currentPage: 1,
          pageSize: 20,
          total: 0,
        },
        list: [],
      };
    },
    mounted() {
      this.getInfo();
    },
    methods: {
      //去创建
      toCreate() {
        let pathUrl = {
          name: 'manageDetil',
          query: {
            processPrimaryKey: this.$route.query.primaryKey,
            processCode: this.$route.query.key,
          },
        };
        this.$router.push(pathUrl);
      },
      //去详情
      toDetil(val) {
        let pathUrl = {
          name: 'manageDetil',
          query: {
            processPrimaryKey: this.$route.query.primaryKey,
            ccType: 'cc',
            key: val.primaryKey,
            processCode: this.$route.query.key,
            primaryKey: val.formKey,
          },
        };
        this.$router.push(pathUrl);
      },
      //列表
      async getInfo(currentPage = 1) {
        this.queryParams.currentPage = currentPage || this.queryParams.currentPage;
        try {
          let param = {
            processCode: this.$route.query.key,
            pageSize: this.queryParams.pageSize,
            currentPage: this.queryParams.currentPage,
          };
          const res = await apiCcManageList(param);
          if (res.success) {
            this.list = res.rows;
            this.queryParams.total = res.total;
          }
        } catch (err) {
          console.log(err);
        }
      },
      //删除
      deleteItem(key) {
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(async () => {
            let res = await apiCcManageListDelect(key);
            if (res.success) {
              this.getInfo();
              this.$message.success('删除成功!');
            } else {
              this.$message.error(res.message);
            }
          })
          .catch(() => {});
      },
    },
    filters: {
      formatDate: formatDate,
    },
  };
</script>
<style lang="scss" scoped>
  .demo-form-inline {
    margin-bottom: 50px;
  }
</style>
